package demoMod.stsconsole.cards.red;

import demoMod.stsconsole.cards.AbstractCard;
import demoMod.stsconsole.characters.AbstractPlayer;
import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.helpers.DamageInfo;
import demoMod.stsconsole.interfaces.CombatStartSubscriber;
import demoMod.stsconsole.interfaces.InflictSubscriber;

public class BloodForBlood extends AbstractCard implements CombatStartSubscriber, InflictSubscriber {
    public static final String ID = "BloodForBlood";

    private static int damagedThisCombat = 0;

    public BloodForBlood() {
        super(ID);
        this.baseDamage = 18;
        this.color = CardColor.RED;
        this.cost = 4 - damagedThisCombat;
        if (this.cost < 0) this.cost = 0;
        this.rarity = CardRarity.UNCOMMON;
        this.type = CardType.ATTACK;
        this.target = CardTarget.ENEMY;
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.baseDamage += 4;
            if (this.cost > 0) this.cost--;
            this.upgraded = true;
            this.name = this.name + "+";
            this.upgradeTimes++;
        }
    }

    @Override
    public boolean use(AbstractPlayer p, AbstractCreature target) {
        if (target != null) {
            target.damage(new DamageInfo(this.damage, p));
        }
        return true;
    }

    @Override
    public void atBattleStart() {
        damagedThisCombat = 0;
        if (this.upgraded) {
            this.cost = 3;
        } else {
            this.cost = 4;
        }
    }

    @Override
    public void onInflictDamage(DamageInfo info, AbstractCreature target) {
        if (target == AbstractDungeon.player) {
            damagedThisCombat++;
            if (this.cost > 0) this.cost--;
        }
    }
}
